#include<iostream>
using namespace std;
double hermite(double s)
{
	int x[10] = { 0,0,3,3,5,5,8,8,13,13 };
	int y[10] = { 0,0,225,225,383,383,623,623,993,993 };
	int z[5] = { 75,77,80,74,72 };
	double diff[10][10] = { 0 };
	for (int i = 0; i < 10; i++) {
		diff[i][0] = y[i];
	}
	for (int j = 1; j < 10; j++) {
		for (int i = j; i < 10; i++) {
			if (x[i] == x[i - j]) diff[i][j] = z[(i+1)/2-1];
			else diff[i][j] = (diff[i][j - 1] - diff[i - 1][j - 1]) / (x[i] - x[i - j]);
		}
	}
	double sum = diff[0][0];
	for (int i = 1; i <=10; i++) {
		double temp = 1;
		for (int j = 0; j < i; j++) {
			temp *= (s - x[j]);
		}
		sum = sum + diff[i][i] * temp;
	}
	return sum;
}
double derivate(double x)
{
	double eps = 0.0001;
	double result = (hermite(x + eps) - hermite(x - eps)) / (2 * eps);
	return result;
}
int main()
{
	int t = 10; int flag = 0;
	double position = hermite(t);
	double v = derivate(t);
	double y[100] = { 0 };
	cout << "10s时汽车的位置：" << position << endl;
	cout << "10s时汽车的速度：" << v << endl;
	for (int i = 0; i < 100; i++) {
		y[i] = derivate(0.13 * (i + 1));
		if (y[i] > 81) {
			flag = 1;
			break;
		}
	}
	if (flag == 1) cout << "该汽车超过了81英尺每秒" << endl;
	else cout << "该汽车没有超过81英尺每秒" << endl;
}
